package org.example.theory.component;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.example.theory.model.Dog;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
public class DogComponent implements BeanNameAware {
    public Dog singletonDog;
    public DogComponent() {
        System.out.println("执行构造方法实例化");
    }

    @Autowired
    public void setSingletonDog(Dog singletonDog) {
        this.singletonDog = singletonDog;
        System.out.println("执行setSingletonDog注入Bean");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("执行setBeanName, BeanName: " + name);
    }


    @PostConstruct
    public void init() {
        //@PostConstruct:表示该方法为初始化方法
        System.out.println("执行init方法初始化");
    }


    public void use() {
        System.out.println("执行use方法");
    }


    @PreDestroy
    public void destroy() {
        System.out.println("执行destroy方法, 进行销毁前处理");
    }
}
